package ro.imc.training.Database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import ro.imc.training.UMS.Profesor;

public class ProfesorCrud implements Crud {

	@Override
	public void insert(Object o) {

		try {

			Connection conn = DriverManager
					.getConnection(DBCreate.DATABASE_URL);

			Profesor prof = (Profesor) o;

			conn.createStatement().execute(
					"insert into student values " + "(' " + prof.getLastName()
							+ "','" + prof.getFirstName() + "','"
							+ prof.getCNP() + "','" + prof.getField() + "','"
							+ prof.getTitle() + " ') ");

		} catch (SQLException e) {

			e.printStackTrace();
		}

	}

	@Override
	public ArrayList<Object> read() {

		ArrayList<Object> al = new ArrayList<Object>();
		try {
			Connection conn = DriverManager
					.getConnection(DBCreate.DATABASE_URL);
			Statement statement = conn.createStatement();
			ResultSet result = statement.executeQuery("select * from profesor");

			while (result.next()) {
				Profesor prof = new Profesor(result.getString(1),
						result.getString(2), result.getString(3),
						result.getString(4), result.getString(5));
				al.add(prof);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return al;

	}

	@Override
	public void update() {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub

	}

}
